#pragma once

#include <wx/wx.h>
#include <wx/fileconf.h>
#include <wx/filename.h>
#include <wx/wfstream.h>
#include <wx/stdpaths.h>

#include "verinfo.h"

class ConfigManager : public wxFileConfig {
public :
	virtual ~ConfigManager() {
		wxLogMessage(_T("ConfigManager::~ConfigManager"));
		this->Flush();
	}
	
    static ConfigManager& get(){
        if(_cfg_mgr==NULL) {
            wxFFileInputStream cfgstrm(app_cfgfile_path.GetFullPath());
            _cfg_mgr = new ConfigManager(cfgstrm);
        }

        return *_cfg_mgr;
    }
    
    virtual bool Flush(bool bCurrentOnly = false) {
        wxFFileOutputStream cfgstrm(app_cfgfile_path.GetFullPath());
        this->Save(cfgstrm);
    }
    
    static void set_appname(const wxString& appname);
	
    
    // const int APP_VERSION_MAJOR;
    // const int APP_VERSION_MINOR;
    // const int APP_VERSION_REVISION;

    
    /** Get global resources directory.
     * Daodict themes locate in this dir. Example return values:
     *   Unix: prefix/share/Daodict
     *   Windows: the directory where the executable file is located
     *   Mac: Daodict.app/Contents/Resources bundle subdirectory
    */
    wxFileName global_res_dir;

    
    /** Get global data directory
     * Example return values:
     *   Unix: prefix/share/Daodict
     *   Windows: the directory where the executable file is located
     *   Mac: Daodict.app/Contents/SharedSupport bundle subdirectory
     */
    wxFileName global_data_dir;

    
    /** Get user data directory.
     *  Return the directory for the user-dependent application data files:
     *    Unix: ~/.DaoDict
     *    Windows: C:\Documents and Settings\username\Application Data\Daodict
     *    Mac: ~/Library/Application Support/Daodict
     */
    wxFileName user_data_dir;
    
    wxFileName product_theme_dir;
    
    wxFileName product_dictpack_dir;
    
    wxFileName product_mgrdb_path;
    
    wxFileName app_logfile_path;
    
    static wxFileName app_cfgfile_path;
    
    /*wxString app_author;
    wxString app_version_string;
    wxString app_website;
    wxString app_email;
    wxString app_description;*/
    
    static wxString appname;

protected :
    void _init_paths();
    
    static ConfigManager* _cfg_mgr;

private :
    ConfigManager(wxInputStream& is);
};

